package com.everflourish.yeah100.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.everflourish.yeah100.R;
import com.everflourish.yeah100.entity.marking.ReadCardRecord;
import com.everflourish.yeah100.utils.CommonUtil;
import com.everflourish.yeah100.utils.constant.RecordType;

import java.util.List;

public class OperationRecordAdapter extends BaseAdapter {

    private List<ReadCardRecord> mRecordList;
    private LayoutInflater mInflater;
    private Context mContext;

    public OperationRecordAdapter(Context context,
                                  List<ReadCardRecord> recordList) {
        this.mRecordList = recordList;
        mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mRecordList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return mRecordList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HolderView holderView = null;
        if (convertView == null) {
            holderView = new HolderView();
            convertView = mInflater.inflate(R.layout.item_record, parent, false);
            holderView.recordError = (LinearLayout) convertView
                    .findViewById(R.id.record_error_ll);
            holderView.recordMsg = (TextView) convertView
                    .findViewById(R.id.record_msg);
            holderView.recordHelp = (TextView) convertView
                    .findViewById(R.id.record_help_tv);
            convertView.setTag(holderView);
        } else {
            holderView = (HolderView) convertView.getTag();
        }
        ReadCardRecord record = mRecordList.get(position);
        if (CommonUtil.isHelpType(record.getRecordType())) {// 帮助
            holderView.recordError.setVisibility(View.VISIBLE);
            holderView.recordMsg.setVisibility(View.GONE);
            holderView.recordHelp.setText(record.getMsg());
        } else {
            holderView.recordError.setVisibility(View.GONE);
            holderView.recordMsg.setVisibility(View.VISIBLE);
            holderView.recordMsg.setText(record.getMsg());
        }
        if (record.getRecordType() == RecordType.not_found_student_id) {// 没有找到学号

        } else if (record.getRecordType() == RecordType.read_card_failure) {// 读卡失败了

        } else if (record.getRecordType() == RecordType.read_student_id_failure) {// 读学号失败了

        } else if (record.getRecordType() == RecordType.read_card_success) {// 读卡成功

        }
        return convertView;
    }

    class HolderView {
        public LinearLayout recordError = null;
        public TextView recordMsg = null;
        public TextView recordHelp = null;
    }
}
